<template>
    <el-dialog title="另存为" :visible.sync="getDialogStatus.stSaveAs">
        <el-input placeholder="请输入文件名" v-model="filename"></el-input>
        <div slot="footer" class="dialog-footer">
            <el-button @click="closeAllDialog">取 消</el-button>
            <el-button type="primary" @click.stop="saveFile">确 定</el-button>
        </div>
        {{getFileName}}
    </el-dialog>
</template>

<script>

import {mapMutations,mapGetters} from 'vuex';
import Hash from '../../../lib/hash.js'
export default {
    props:{
        
    },
    data() {
        return {
            filename:'',
        };
    },
    computed:{
        ...mapGetters(['getDialogStatus','getCurrentActiveTable','getTables']),
        getFileName(){
           
        }
    },
    watch:{
        filename(newVal,oldVal){

        }
    },
    methods:{
        ...mapMutations(['setDialogStatus','closeAllDialog']),
        
        saveFile(){
            if(!this.getCurrentActiveTable){
                this.$message({
                    message: '没有可用的表格！',
                    type: 'warning'
                });
                this.closeAllDialog();
                return;
            }
            if(this.filename.replace(/\s+/g,"")==""){
                this.$message({
                    message: '文件名不能为空！',
                    type: 'warning'
                });
                return;
            }

            let index=this.getCurrentActiveTable.index;
            let table=this.getTables[index];
            let hash=new Hash();
            axios.post(config.PATH+'main_table',{
                id:hash.gethashcode(),
                filename:this.filename,
                data:{
                    sourceData:table.data,
                    mergeCells:table.mergeCells,
                    sourceURL:table.sourceURL,
                    preHashTable:table.preHashTable,
                    colWidths:table.colWidths,
                    rowHeights:table.rowHeights
                },
            }).then((res)=>{
                if(res.data.msg){
                    this.$message({
                        type:'success',
                        message: '文件另存成功',
                    })
                    this.closeAllDialog();
                }
            },(res)=>{
                this.$message({
                    type:'success',
                    message: `保存失败${res.data}`,
                })
            });
            this.setDialogStatus({
               key:"stSaveFile",
               value:false
            });
        },
    }
}
</script>

<style>

</style>
